using Godot;
using System;

public partial class Main : Node
{
	[Export]
	PackedScene endScreenScene;
	PackedScene pauseMenuScene = GD.Load<PackedScene>("res://scenes/ui/pause_menu.tscn");
	MetaProgression metaProgression;
	// Called when the node enters the scene tree for the first time.
	public override void _Ready()
	{
		GetNode<Player>("%Player").healthComponent.Died += OnPlayerDied;
		
		metaProgression = GetNode<MetaProgression>("/root/MetaProgression");

	}

    public override void _UnhandledInput(InputEvent @event)
    {
		if(@event.IsActionPressed("pause")){
			AddChild(pauseMenuScene.Instantiate());
			GetTree().Root.SetInputAsHandled();
		}
        base._UnhandledInput(@event);
    }

    // Called every frame. 'delta' is the elapsed time since the previous frame.
    public override void _Process(double delta)
	{
	}

	public void OnPlayerDied(){
		EndScreen endScreen = endScreenScene.Instantiate() as EndScreen;
		AddChild(endScreen);
		endScreen.SetDefeat();
		metaProgression.Save();
	}
}
